import axios from '@/utils/request'
// 登录API
export const login = ({ phone, code }) => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: phone,
      code
    }
  })
}
// 频道的API
export const getChannelAPI = () => {
  return axios({
    url: '/v1_0/channels'
  })
}
// 获取文章的API
export const getArticleAPI = ({ status, channel_id, begin_pubdate, end_pubdate, page = 1, per_page = 10 }) => {
  return axios({
    url: '/v1_0/mp/articles',
    params: {
      status,
      channel_id,
      begin_pubdate,
      end_pubdate,
      page,
      per_page

    }
  })
}
// 删除文章
export const delArticleAPI = (id) => {
  return axios({
    url: '/v1_0/mp/articles/' + id,
    method: 'DELETE'
  })
}
// 发表文章
export const setArticleAPI = ({ draft = false, title, content, cover, channel_id }) => {
  return axios({
    url: '/v1_0/mp/articles',
    method: 'POST',
    params: {
      draft
    },
    data: {
      title,
      content,
      cover,
      channel_id
    }
  })
}
// 获取一遍文章
export const getOneArticleAPI = (id) => {
  return axios({
    url: '/v1_0/mp/articles/' + id
  })
}
// 编辑文章
export const editArticleAPI = ({ id, draft = false, title, content, cover, channel_id }) => {
  return axios({
    url: '/v1_0/mp/articles/' + id,
    method: 'PUT',
    params: {
      draft
    },
    data: {
      title,
      content,
      cover,
      channel_id
    }

  })
}
